package com.jf.blog.util;

import lombok.Data;

@Data
public class ResultJson {

    private static final Integer SUCCESS_CODE = 200;
    private static final Integer ERROR_CODE = 500;
    private static final String SUCCESS_MSG = "success";
    private static final String ERROR_MSG = "服务器异常，请稍后再试";


    private Integer code;
    private String msg;
    private Object data;

    private ResultJson(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResultJson() {
        this.code = SUCCESS_CODE;
        this.msg = SUCCESS_MSG;
    }

    private static ResultJson init(Integer code, String msg) {
        return new ResultJson(code, msg);
    }

    public static ResultJson success(String msg) {
        ResultJson resultJson = new ResultJson();
        resultJson.setMsg(msg);
        return resultJson;
    }

    public static ResultJson success() {
        return new ResultJson();
    }

    public static ResultJson success(Object data) {
        ResultJson resultJson = new ResultJson();
        resultJson.setData(data);
        return resultJson;
    }

    public static ResultJson error(Integer code, String msg) {
        return init(code, msg);
    }

    public static ResultJson error(Integer code) {
        return error(code, ERROR_MSG);
    }

    public static ResultJson error(String msg) {
        return error(ERROR_CODE, msg);
    }

}
